package org.example.springboot.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.example.springboot.model.Products;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ProductsMapper extends BaseMapper<Products> {


    @Insert("insert into products (product_image, product_name, model_number, serial_number, service_code, supplier_name, category, purchase_price, sale_price, warranty_period, status, stock, in_order_id, out_order_id, customer_name, project_name, sales_team, after_sales_team, notes) values (#{productImage},#{productName},#{modelNumber},#{serialNumber}, #{serviceCode},#{supplierName},#{category},#{purchasePrice},#{salePrice}, #{warrantyPeriod},#{status},#{stock},#{inOrderId},#{outOrderId}, #{customerName},#{projectName}, #{salesTeam},#{afterSalesTeam}, #{notes})")
    int insertProduct(@Param("productImage") String productImage, @Param("productName") String productName, @Param("serialNumber") String serialNumber, @Param("modelNumber") String modelNumber, @Param("serviceCode") String serviceCode,@Param("supplierName") String supplierName, @Param("category") String category, @Param("purchasePrice") String purchasePrice, @Param("salePrice") String salePrice, @Param("warrantyPeriod") String warrantyPeriod,@Param("status") String status, @Param("stock") String stock, @Param("inOrderId") String inOrderId, @Param("outOrderId") String outOrderId, @Param("customerName") String customerName,@Param("projectName") String projectName, @Param("salesTeam") String salesTeam, @Param("afterSalesTeam") String afterSalesTeam, @Param("notes") String notes);

    @Select("select * from products")
    List<Products> getAllProduct();

    @Select("select * from products where id = #{id}")
    Products getProductById(@Param("id")int id);

    @Select("select * from products " + "where product_name like CONCAT('%', #{keyword}, '%') " + "or model_number like CONCAT('%', #{keyword}, '%')"+ "or supplier_name like CONCAT('%', #{keyword}, '%')"+ "or stock_status like CONCAT('%', #{keyword}, '%')")
    List<Products> findProductByKeyword(@Param("keyword")String keyword);

    @Delete("delete from products where id = #{id}")
    void deleteProductById(@Param("id")int id);

    @Update("update products set stock =#{stock} where id = #{id}")
    void updateProductStock(String stock,int id);
}
